<?php use_helper('jQuery')?>

<fieldset id="<?php echo sprintf('option_%d', $num)?>">
    <legend>Opción</legend>
    <div class="form-row">
        <?php echo $form['Menu']['Options'][$num]['is_local']->renderLabel() ?>
        <div class="form-field">
            <?php echo $form['Menu']['Options'][$num]['is_local']->renderError() ?>
            <?php echo $form['Menu']['Options'][$num]['is_local']->render() ?>
        </div>
    </div>
    <div id="<?php echo 'menu_option_local_'.$num ?>"
         style="display: <?php echo ($form->getObject()->getMenu()->getOptions()->get($num)->getIsLocal() ? 'block' : 'none')?>">
        <div class="form-row">
            <?php echo $form['Menu']['Options'][$num]['section_id']->renderLabel() ?>
            <div class="form-field">
                <?php echo $form['Menu']['Options'][$num]['section_id']->renderError() ?>
                <?php echo $form['Menu']['Options'][$num]['section_id']->render() ?>
            </div>
        </div>
    </div>
    <div id="<?php echo 'menu_option_external_'.$num ?>"
         style="display: <?php echo ($form->getObject()->getMenu()->getOptions()->get($num)->getIsLocal() ? 'none' : 'block')?>">
        <div class="form-row">
            <?php echo $form['Menu']['Options'][$num]['title']->renderLabel() ?>
            <div class="form-field">
                <?php echo $form['Menu']['Options'][$num]['title']->renderError() ?>
                <?php echo $form['Menu']['Options'][$num]['title']->render() ?>
            </div>
        </div>
        <div class="form-row">
            <?php echo $form['Menu']['Options'][$num]['link']->renderLabel() ?>
            <div class="form-field">
                <?php echo $form['Menu']['Options'][$num]['link']->renderError() ?>
                <?php echo $form['Menu']['Options'][$num]['link']->render() ?>
            </div>
        </div>
    </div>
    <?php if(isset ($form['Menu']['Options'][$num]['is_enabled'])):?>
        <div class="form-row">
            <?php echo $form['Menu']['Options'][$num]['is_enabled']->renderLabel() ?>
            <div class="form-field">
                <?php echo $form['Menu']['Options'][$num]['is_enabled']->renderError() ?>
                <?php echo $form['Menu']['Options'][$num]['is_enabled']->render() ?>
            </div>
        </div>
    <?php else: ?>
        <?php if($num>0):?>
            <div class="form-row">
                <a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
                   id="<?php echo 'option_'.$num ?>" href="#" aria-disabled="false">
                    <span class="ui-button-icon-primary ui-icon ui-icon-minusthick"></span>
                    <span class="ui-button-text">Eliminar</span>
                </a>
            </div>
        <?php endif;?>
    <?php endif;?>
</fieldset>

<?php echo jq_javascript_tag("
        $('a#option_".$num."').click(function() {
            removeFromForm($(this).parent().parent());
        });
    ")?>

<?php echo jq_javascript_tag()?>
    $('input#ems_element_Menu_Options_<?php echo $num ?>_is_local_1').change(
        function(){
            if($(this).is(':checked')){
                $('div#menu_option_local_<?php echo $num ?>').fadeIn("slow");
                $('div#menu_option_external_<?php echo $num ?>').fadeOut("slow");
            }
        }
    );
    $('input#ems_element_Menu_Options_<?php echo $num ?>_is_local_0').change(
        function(){
            if($(this).is(':checked')){
                $('div#menu_option_local_<?php echo $num ?>').fadeOut("slow");
                $('div#menu_option_external_<?php echo $num ?>').fadeIn("slow");
            }
        }
    );
<?php echo jq_end_javascript_tag()?>